﻿using System;

namespace Shape1
{
    class Program
    {
        abstract class Shape
        {
            public double l;
            public double L
            {
                get { return l; }
                set { l = value; }
            }

            public double h;
            public double H
            {
                get { return h; }
                set { h = value; }
            }

            public double r;
            public double R
            {
                get { return r; }
                set { r = value; }
            }
            //area
            public abstract void Area();

            static void Main(string[] args)
            {
                //长方形
                Rectangle rectangle = new Rectangle();
                rectangle.Area();
                //正方形
                Square square = new Square();
                square.Area();
                //三角形
                Triangle triangle = new Triangle();
                triangle.Area();

            }
        }
        //长方形
        class Rectangle : Shape
        {
            public override void Area()
            {
                double sum = 0;
                Console.WriteLine("下面计算一个长方形的面积，请输入长：");
                L = double.Parse(Console.ReadLine());
                Console.WriteLine("请输入宽：");
                H = double.Parse(Console.ReadLine());
                sum =  L * H;
                if(L>0&&H>0)
                {
                    Console.WriteLine("这个长方形的面积是：" + sum + "");
                }
                else
                {
                    Console.WriteLine("抱歉，您输入的长方形不合法。");
                }
                Console.ReadLine();
            }
        }
        //正方形
        class Square : Shape
        {
            public override void Area()
            {
                double sum = 0;
                Console.WriteLine("下面计算一个正方形的面积，请输入边长：");
                L = double.Parse(Console.ReadLine());
                sum = L * L;
                if (L > 0 )
                {
                    Console.WriteLine("这个正方形的面积是：" + sum + "");
                }
                else
                {
                    Console.WriteLine("抱歉，您输入的正方形不合法。");
                }
                Console.ReadLine();
            }
        }
        //三角形
        class Triangle : Shape
        {
            public override void Area()
            {
                double sum = 0;
                Console.WriteLine("下面计算一个三角形的面积，请输入底：");
                L = double.Parse(Console.ReadLine());
                Console.WriteLine("请输入高：");
                H = double.Parse(Console.ReadLine());
                sum = 0.5 * L * H;
                if (L > 0 && H > 0)
                {
                    Console.WriteLine("这个三角形的面积是：" + sum + "");
                }
                else
                {
                    Console.WriteLine("抱歉，您输入的三角形不合法。");
                }
                Console.ReadLine();
            }
        }

    }
}
